package Pattern.StrategyPattern;

import Pattern.StrategyPattern.fly.FlyBehavior;
import Pattern.StrategyPattern.fly.FlyNoWay;
import Pattern.StrategyPattern.quack.QuackBehavior;

/**
 *@author Antionia
 * @version 1.0.0
 * @see抽象超类Duck
 */
public abstract class Duck{
    protected FlyBehavior   flyBehavior;
    protected QuackBehavior quackBehavior;

    public void swim(){
        System.out.println("Swimming");
    }

    public abstract void display();

    public void performQuack(){
        quackBehavior.quack();
    }

    public void performFly(){
        flyBehavior.fly();
    }

    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
    }

    public void setQuackBehavior(QuackBehavior quackBehavior) {
        this.quackBehavior = quackBehavior;
    }

    public static void main(String[] args) {
      Duck duck=new MallarDuck();
      duck.performFly();
      duck.performQuack();
      duck.setFlyBehavior(new FlyNoWay());
      duck.performFly();
    }
}
